//编写注册函数；
#include"../include/p.h"
int myregister(int newfd,sqlite3 *mydb,char *tbname,char *buf)
{
	//1解析字符串 把 传过来的字符串分解成三个字符串 
	//1.id 2.用户名 3.密码；
	//调用解析字符串
	char id[20]={0};
	char usrname[20]={0};
	char pwd[20]={0};

	parsestr1(buf,id,usrname,pwd);
	printf("%s",id);
	//插入结构体；
	Usermsg mymsg;
	memset(&mymsg,0,sizeof(mymsg));
	mymsg.userID=atoi(id);
	printf("%d",mymsg.userID);
	sprintf(mymsg.username,"%s",usrname);
	sprintf(mymsg.pwd,"%s",pwd);
	int ret=insert_db(mydb,tbname,mymsg);
	if(ret<0)
	{
		printf("insert error ");
		
		send(newfd,"注册失败",sizeof(4),0);
		return -1;
	
	}
	char zhucebuf[1000]={"0"};
	sprintf(zhucebuf,"注册成功！欢迎 %s 登录!",mymsg.username);
	printf("%s\n",zhucebuf);
	send(newfd,zhucebuf,sizeof(zhucebuf),0);
	return 0;


}
